##PBAR_ReadFD.py

import os
import csv
import numpy as np


fid = open('C:\Users\jkwong\Documents\Work\PBAR\data\dy97_FD-det24.txt', 'r')

csvReaderObj = csv.reader(fid, delimiter = ',')

# ma
dat = np.zeros((256, 256))

for ii in range(32):
    startIndex = ii*16
    stopIndex = (ii+1)*16

    # make temporary array for storing
    temp = np.zeros((256,16))    
    for jj in range(256):  # read 256 rows of the 18 columns
        # truncate row number and last element (which is blank) and convert to float
        temp[jj,:] = (np.array(csvReaderObj.next()))[1:-1].astype(float)
    dat[:, startIndex:stopIndex] = temp
    # skip to lines
    csvReaderObj.next()
    csvReaderObj.next()
fid.close()
